package com.yesorno.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yesorno.constants.Constants;
import com.yesorno.model.HttpResponseObject;
import com.yesorno.ui.CustomTitleActivity;
import com.yesorno.utils.HttpUtils;

public class PersonalMessageRecallActivity extends CustomTitleActivity {

	private Button goBack;// 返回
	private Button send;// 发送

	private EditText personal_message_recall_desc;

	HallBtnsClickListeners rbc = new HallBtnsClickListeners();

	private long userId;
	private long messageId;

	/**
	 * 大厅页面按钮的监听类
	 * 
	 * @author samoin
	 * @date 2011-07-06
	 * @version 0.1
	 * 
	 */
	class HallBtnsClickListeners implements OnClickListener {
		@Override
		public void onClick(View v) {

			if (v == goBack) {
				Intent intent = new Intent();
				PersonalMessageRecallActivity.this.setResult(RESULT_OK, intent);
				PersonalMessageRecallActivity.this.finish();
			}
			if (v == send) {
				String desc = personal_message_recall_desc.getText().toString();
				//TODO 进行通讯，发送回复信息
				HttpResponseObject hro = HttpUtils.getInfoByUrlPost(
						Constants.USER_MESSAGE_LIST_URL + "userId=" + userId
								+ "&messageId=" + messageId + "&curUserId="
								+ Constants.USER_ID + "&desc=" + desc,
						PersonalMessageRecallActivity.this);
				// if(hro.getCode() == 1){
				Intent intent = new Intent();
				intent.setClass(PersonalMessageRecallActivity.this, TopicListActivity.class);
				startActivity(intent);
				// }
			}
		}
	}

	@Override
	public void setTitleViews() {
		LinearLayout titleLayout = getTITLE_LAYOUT();

		goBack = CustomTitleActivity.createTitleLeftButton(
				PersonalMessageRecallActivity.this,
				R.string.reg_title_btn_goback, Constants.TITLE_BTN_MARGIN1);
		goBack.setOnClickListener(rbc);
		titleLayout.addView((View) goBack.getParent());

		TextView tv = CustomTitleActivity.createTitleDesc(
				PersonalMessageRecallActivity.this,
				R.string.user_message_title, 0);
		titleLayout.addView((View) tv.getParent());

		send = CustomTitleActivity.createTitleRightButton(
				PersonalMessageRecallActivity.this,
				R.string.personal_message_recall_send,
				Constants.TITLE_BTN_MARGIN2);
		LinearLayout ll = (LinearLayout) send.getParent();
		ll.setGravity(Gravity.RIGHT);
		send.setOnClickListener(rbc);
		titleLayout.addView(ll);

	}

	@Override
	public void setLayoutId() {
		setContentView(R.layout.personal_message_recall);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		userId = getIntent().getLongExtra("currentUserId", 0);
		messageId = getIntent().getLongExtra("currentMessageId", 0);

		super.onCreate(savedInstanceState);

		personal_message_recall_desc = (EditText) findViewById(R.id.personal_message_recall_desc);
	}

}
